package com.gitee.wsl.coroutines.executor

import com.gitee.wsl.concurrent.api.RunnableWithResult
import com.gitee.wsl.concurrent.api.SuspendRunnable
import com.gitee.wsl.concurrent.api.SuspendRunnableWithResult
import com.gitee.wsl.platform.concurrent.runBlocking
import com.gitee.wsl.concurrent.executor.Executor
import kotlinx.coroutines.Runnable

interface KExecutor: Executor {
    override val isDisposed: Boolean
        get() = false

    fun <T> execute(block: RunnableWithResult<T>):T

    override fun exec(runnable: Runnable) = execute(runnable::run)

    override fun dispose() {}

    companion object
}

interface SuspendKExecutor: KExecutor {

    suspend fun <T> executeSuspend(block: SuspendRunnableWithResult<T>): T

    suspend fun execSuspend(block: SuspendRunnable) = executeSuspend(block::run)

    override fun <T> execute(block: RunnableWithResult<T>): T = runBlocking{
        executeSuspend{ block.run() }
    }
}


/**
 * CountedThreads is an interface that represents a collection of threads.
 * It provides methods to retrieve the count of active tasks and total tasks.
 */
interface CountedTasksExecutor:KExecutor {

    fun getActiveTasksCount():Long

    fun getTotalTasksCount():Long

}